package model;

import dao.Reservation_MesaDAO;
import dao.MesaDAO;
import dao.ReservationDAO;

public class Reservation_Mesa {
	
	private int mesa_id;
	private int reservation_id;
			
	private Reservation_MesaDAO reservation_mesaDAO;
	private ReservationDAO reservationDAO;
	private MesaDAO mesaDAO;
	
	public Reservation_Mesa() {
		reservation_mesaDAO = new Reservation_MesaDAO();
		mesaDAO = new MesaDAO();
		reservationDAO = new ReservationDAO();
		
	}
	
	public int getMesa_id() {return mesa_id;}
	public int getReservation_id() {return reservation_id;}
	
	public void setMesa_id(int mesa_id) {this.mesa_id = mesa_id;}
	public void setReservation_id(int reservation_id) {this.reservation_id = reservation_id;}

	public String reservarMesa(int res_id, int mesa_id) {
		Mesa m = mesaDAO.select(mesa_id);
		Reservation r = reservationDAO.select(res_id);
		
		if( r == null || r.getActive() == 0) {
			return "Reservacion inexistente";
		}
		
		if( m == null || m.getBusy() == 1) {
			return "Mesa ocupada";
		}
		
		else {
			m.setBusy(1);
			mesaDAO.update(m);
			
			Reservation_Mesa rm = new Reservation_Mesa();
			rm.setMesa_id(mesa_id);
			rm.setReservation_id(res_id);
			reservation_mesaDAO.create(rm);
			
			return "success";
		}		
	}
}
